package com.atguigu.springcloud.consumer;

import com.atguigu.springcloud.config.RabbitMQConst;
import com.atguigu.springcloud.entity.MovieTicketInfo;
import com.atguigu.springcloud.service.impl.IMovieTikectServiceImpl;
import com.atguigu.springcloud.utils.MovieFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author zhenyu
 * @desc 消费者
 * @Date 2022/10/18 15:11
 * @Version 1.0
 */
@Component
@Slf4j
public class Consumer {

  @Autowired
  private IMovieTikectServiceImpl iMovieTikectService;

  @Autowired
  private MovieFeignService movieFeignService;

  /**
   * 保存购票信息
   *
   * @param movieTicketInfo
   */
  @RabbitListener(queues = RabbitMQConst.MOVIE_TICKET_QUEUE)
  public void process(MovieTicketInfo movieTicketInfo) {
    log.info("购票信息为：" + movieTicketInfo);
    iMovieTikectService.getBaseMapper().insert(movieTicketInfo);
    log.info("保存购票信息完成...");
    log.info("开始更新电影票信息...");
    movieFeignService.updateMovieNum(movieTicketInfo.getMovieId(), movieTicketInfo.getNumber());
    log.info("更新电影票信息完成...");
  }

}
